
var config = require("./config.js");
// var webpack = require('webpack');
var htmlWebpackPlugin = require('html-webpack-plugin');
var extractTextPlugin = require("extract-text-webpack-plugin");
// var es3ifyPlugin = require('es3ify-webpack-plugin');
// var UglifyJS = require("uglify-js");

var loaders = [
    // { test: /\.vue$/, loader: 'vue-loader' },
    { test: /\.html$/, loader: "html-loader" },
    {
        test: /\.(png|gif|jpe?g)$/, loader: 'url-loader',
        query: {
            limit: 1,
            name: 'images/[hash:8].[ext]'
            // name: '/images/[hash:8].[ext]'
        }
    },
    {
        test: /\.(eot|woff|woff2|ttf|svg)$/,
        loader: 'url-loader',
        query: {
            limit: 1,
            name: '/font/[name]-[hash:8].[ext]'
        }
    },
    {
        test: /\.css$/,
        loader: extractTextPlugin.extract({
            fallback: 'style-loader',
            use: 'css-loader'
        })
    },
    {
        test: /\.ts$/,
        loader: 'ts-loader'
    }
];

var plugins = [
    new htmlWebpackPlugin({
        template: config.devPath + 'index.html',
        inject: 'body',
        minify: {
            removeComments: true,
            collapseWhitespace: true,
            removeAttributeQuotes: true
            // more options:
            // https://github.com/kangax/html-minifier#options-quick-reference
        },
        chunksSortMode: 'dependency'
    }),
    new extractTextPlugin({ filename: 'css/[name]-[chunkhash:8].css', disable: false, allChunks: true })
    // new webpack.DefinePlugin({
    //     __SERVICES__: JSON.stringify(path.resolve(__dirname, 'services')),
    //     __LIBS__: JSON.stringify(path.resolve(__dirname, 'libs')),
    //     __VIEWS__: JSON.stringify(path.resolve(__dirname, 'src', 'tw', 'tkc', 'views')),
    //     __COMPONENTS__: JSON.stringify(path.resolve(__dirname, 'src', 'tw', 'tkc', 'components')),
    //     __MAIN__: JSON.stringify(path.resolve(__dirname, 'src', 'tw', 'tkc', 'main'))
    // }),
    // new webpack.optimize.UglifyJsPlugin({
    //     compress: {
    //         warnings: false
    //     },
    //     output: {
    //         comments: false
    //     },
    //     mangle: false,
    // }),
    // new webpack.optimize.DedupePlugin(), // 查找相等或近似的模块，避免在最终生成的文件中出现重复的模块
    // new es3ifyPlugin()
];

module.exports = {
    entry: config.devPath + 'main.ts',
    output: {
        path: config.devPath + 'build/',
        filename: 'js/[chunkhash:8].js'
    },

    module: {
        loaders: loaders
    },

    plugins: plugins,

    devServer: {
        contentBase: config.devPath,
        port: config.devPort
    }
};
console.log(config.devPath, config.devPort)





